import QtQuick 2.15
import QtQuick.Controls 2.15

Item {
    id: root
    
    property string imageSource: ""
    property bool animationRunning: false
    property real rotationAngle: 0
    
    function toggleAnimation() {
        if (animationRunning) {
            rotationAnimation.pause()
        } else {
            rotationAnimation.resume()
        }
        animationRunning = !animationRunning
    }
    
    // 如果没有图片源，使用彩色矩形代替
    Rectangle {
        id: imageRect
        anchors.fill: parent
        color: root.imageSource === "" ? "#FF9800" : "transparent"
        radius: 8
        
        Image {
            id: image
            anchors.fill: parent
            source: root.imageSource !== "" ? root.imageSource : ""
            fillMode: Image.PreserveAspectFit
            smooth: true
            visible: root.imageSource !== ""
        }
        
        // 如果没有图片，显示一个简单的图标
        Text {
            anchors.centerIn: parent
            text: "🔄"
            font.pixelSize: parent.height * 0.6
            visible: root.imageSource === ""
        }
        
        transform: Rotation {
            id: rotation
            origin.x: imageRect.width / 2
            origin.y: imageRect.height / 2
            angle: root.rotationAngle
        }
    }
    
    NumberAnimation on rotationAngle {
        id: rotationAnimation
        from: 0
        to: 360
        duration: 2000
        loops: Animation.Infinite
        running: false
    }
    
    Component.onCompleted: {
        rotationAnimation.start()
        animationRunning = true
    }
}

